<template>
	<view>
		<view class="integralBox">
			<view class="integralTop">
				<image src="/static/user/messageIcon.png" mode=""></image>
				<text>我的积分</text>
				<view class="integralMore" @click="goLog">
					积分明细
					<u-icon name="arrow-right" color="#aaa" size="28"></u-icon>
				</view>
			</view>
			<view class="integralNum">
				{{userInfo.integral}}
			</view>
		</view>

		<view class="integralTitle">积分任务</view>

		<view class="taskItem" v-for="(item,index) in taskList" :key="index">

			<!-- 分享按钮 -->
			<template v-if="item.doing_type=='share'">
				<button open-type="share" hover-class="none">

					<view class="taskIcon">
						<image :src="item.icon_url" mode=""></image>
					</view>
					<view class="taskMain">
						<text class="taskTitle">{{item.title}}</text>
						<text class="taskText">{{item.describe}}</text>
					</view>
					<view class="taskBtn">
						<text class="taskNum">+{{item.num}}积分</text>
						<text class="taskDoing" v-if="item.is_end==1">{{item.btn_end}}</text>
						<text class="taskDoing taskDoingActive" v-if="item.is_end==0">{{item.btn_text}}</text>
					</view>

				</button>
			</template>

			<!-- 跳转页面完成 -->
			<template v-if="item.doing_type=='page'">
				<button hover-class="none" @click="goPage(item.target_page,item.id)">
					<view class="taskIcon">
						<image :src="item.icon_url" mode=""></image>
					</view>
					<view class="taskMain">
						<text class="taskTitle">{{item.title}}</text>
						<text class="taskText">{{item.describe}}</text>
					</view>
					<view class="taskBtn">
						<text class="taskNum">+{{item.num}}积分</text>
						<text class="taskDoing" v-if="item.is_end==1">{{item.btn_end}}</text>
						<text class="taskDoing taskDoingActive" v-if="item.is_end==0">{{item.btn_text}}</text>
					</view>
				</button>
			</template>

			<!-- 上传图片 -->
			<template v-if="item.doing_type=='upload'">
				<button hover-class="none" @click="goPage(item.target_page)">
					<view class="taskIcon">
						<image :src="item.icon_url" mode=""></image>
					</view>
					<view class="taskMain">
						<text class="taskTitle">{{item.title}}</text>
						<text class="taskText">{{item.describe}}</text>
					</view>
					<view class="taskBtn">
						<text class="taskNum">+{{item.num}}积分</text>
						<text class="taskDoing" v-if="item.is_end==1">{{item.btn_end}}</text>
						<text class="taskDoing taskDoingActive" v-if="item.is_end==0">{{item.btn_text}}</text>
					</view>
				</button>
			</template>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskList: [],
				userInfo: {
					integral: 0
				},
				douyinData:{},
				shareData:{},
			}
		},
		onShow() {
			var _this = this;
			_this.getUserInfo();
			_this.getTaskList();
		},
		onShareAppMessage(res) {
			this.addShareLog('new')
			return {
				title: '给你推荐一个好用记工记账小程序',
				path: '/pagesOther/user/shareImg?leader_id=' + this.userInfo.id,
				imageUrl: '/static/sharePic.jpg',
			}
		},
		methods: {
			
			//添加分享记录
			addShareLog(type){
				var _this = this;
				_this.$u.post('/api/plus.report/addShareLog', {
					type:type,
				}).then(res => {
					
				}).catch(res => {
					console.log(res);
				})
			},
			
			// 积分明细
			goLog() {
				uni.navigateTo({
					url: './integralList'
				})
			},
			
			// 获取用户信息
			getUserInfo() {
				var _this = this;
				_this.$u.get('/api/user.index/getDetail', {}).then(res => {
					_this.userInfo = res.data;
				}).catch(res => {
					console.log(res);
				})
			},

			// 获取任务列表
			getTaskList() {
				var _this = this;
				_this.$u.get('/api/project.task/getList', {}).then(res => {
					_this.taskList = res.data;
					_this.shareData=res.extend.shareData;
					_this.douyinData=res.extend.douyinData;
				}).catch(res => {
					console.log(res);
				})
			},

			//跳转页面
			goPage(url,type=0) {
				console.log(url)
				uni.navigateTo({
					url: url
				})
				console.log(type)
				if(type>2){
					this.addShareLog(type)
				}
				
			},
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	.integralBox {
		background-color: #F5F6F8;
		padding: 20rpx;
		border-radius: 20rpx;
		width: 690rpx;
		margin: 20rpx auto;

	}

	.integralTop {
		overflow: hidden;
		padding-top: 10rpx;
		color: $uni-color-text;
		font-size: 28rpx;
	}

	.integralTop image {
		width: 36rpx;
		height: 36rpx;
		vertical-align: top;
	}

	.integralMore {
		float: right;
	}

	.integralNum {
		font-weight: bold;
		font-size: 40rpx;
		padding: 20rpx 20rpx 10rpx 4rpx;
	}

	//标题
	.integralTitle {
		padding: 10rpx 30rpx;
		font-size: 28rpx;
	}

	//任务列表
	.taskItem {
		width: 690rpx;
		background-color: #F5F6F8;
		border-radius: 20rpx;
		margin: 20rpx auto 20rpx auto;
		padding: 30rpx;
		overflow: hidden;
	}

	.taskItem button {
		text-align: left;
	}

	.taskIcon {
		width: 100rpx;
		height: 100rpx;
		float: left;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.taskIcon image {
		width: 100%;
		height: 100%;
	}

	.taskMain {
		width: 340rpx;
		float: left;
		margin-left: 20rpx;
		font-size: 24rpx;
	}

	.taskMain text {
		display: block;
		line-height: 50rpx;
	}

	.taskMain text.taskTitle {
		font-size: 28rpx;
		color: $uni-color;
	}

	.taskMain text.taskText {
		font-size: 28rpx;
		color: $uni-color-text;
	}

	.taskBtn {
		width: 160rpx;
		float: right;
		text-align: right;
		margin-top: 4rpx;
	}

	.taskBtn text {}

	.taskBtn text.taskNum {
		font-size: 26rpx;
		font-weight: bold;
		color: $uni-color;
		display: block;
		height: 30rpx;
		line-height: 30rpx;
		margin-bottom: 20rpx;
	}

	.taskBtn text.taskDoing {
		background-color: #ECEDEF;
		padding: 10rpx 20rpx;
		font-size: 24rpx;
		border-radius: 16rpx;
		color: $uni-color;
	}

	.taskBtn text.taskDoingActive {
		color: $uni-color-white;
		background-color: $uni-color-active;
	}
</style>
